home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / math.swg / 0101_More on PERCENT..pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  400 b   |  20 lines

  1.  
  2. function percent(p,t:longint):longint;
  3. begin
  4.   percent:=trunc(100*(p/t));
  5. end;
  6.  
  7. There you go!  :)  p is the partial value, t is the total value, as in...
  8.  
  9. percent(50,100) = 50%
  10.  
  11. If you want it to return a string instead of a longint, do it like this:
  12.  
  13. function percent(p,t:longint):string;
  14. var s:string; l:longint;
  15. begin
  16.   l:=trunc(100*(p/t));
  17.   str(l,s);
  18.   percent:=s+'%';
  19. end;
  20.